log using reg_main, replace

*Produces the results presented in Table W7
reghdfe vald vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd if  nom==1, abs(k_y_p)
outreg2 using Table_W7, replace dec(3) excel  ctitle(slang)
foreach sample in est_sample   {
preserve 
keep if  `sample'==1 & nom==1 
	foreach comp in vald_prev std_betyg_sd std_cognitive std_std_inc_res{
	foreach pos in     vald_prom listleader_prom vald_ri_prom {
			reghdfe `pos'_rel  `comp' stud age_b30- age_ab64 woman non_nordic non_oecd , abs(k_y_p)
			outreg2 using Table_W7, append dec(3) excel  ctitle(`comp'_`pos')
			
		}
	
	}
restore
}
 
*Produces the results presented in the 3 lower panes of Table 1
reghdfe vald worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd if  nom==1, abs(k_y_p)
outreg2 using Table_1pol, replace dec(3) excel  ctitle(slang)
foreach sample in est_sample   {
	foreach pos in vald_prom listleader_prom vald_ri_prom {
		preserve 
		keep if  `sample'==1 & nom==1 & `pos'!=.
		reghdfe `pos'_rel  worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd   if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_1pol, append dec(3) excel  ctitle(1 `pos'_`sample')
		reghdfe `pos'_rel worker_lim i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd  if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_1pol, append dec(3) excel  ctitle(2 `pos'_`sample')
		reghdfe `pos'_rel worker_lim  std_inc_res i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_1pol, append dec(3) excel  ctitle( 3 `pos'_`sample')
		reghdfe `pos'_rel worker_lim i.vald_prev std_inc_res stud age_b30- age_ab64 woman non_nordic non_oecd     if `sample'==1 & nom==1 & betyg_sd!=. , abs(k_y_p)
		outreg2 using Table_1pol, append dec(3) excel  ctitle(4 `pos'_`sample')
		reghdfe `pos'_rel worker_lim  betyg_sd std_inc_res  i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_1pol, append dec(3) excel  ctitle(5 `pos'_`sample')
		reghdfe `pos'_rel worker_lim i.vald_prev std_inc_res stud age_b30- age_ab64 woman non_nordic non_oecd     if `sample'==1 & nom==1 & cognitive!=., abs(k_y_p)
		outreg2 using Table_1pol, append dec(3) excel  ctitle(6 `pos'_`sample')
		reghdfe `pos'_rel worker_lim  std_inc_res cognitive i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_1pol, append dec(3) excel  ctitle(7 `pos'_`sample')
		restore
	}
}

*Produces the results presented in the 3 lower panes of Table 2
reghdfe vald worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd if  nom==1, abs(k_y_p)
outreg2 using Table_2, replace dec(3) excel  ctitle(slang)
foreach pos in    vald_prom listleader_prom vald_ri_prom  {
	foreach sample in left notleft  {
		preserve 
		keep if  `sample'==1 & nom==1 & `pos'!=. & year>2000 & est_sample==1
		reghdfe `pos'_rel worker_lim_noun worker_lim_un std_inc_res i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_2, append dec(3) excel  ctitle(`pos'_`sample')
		restore
	}
}

*Produces the results presented in the 3 lower panes of Table W8
reghdfe vald worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd if  nom==1, abs(k_y_p)
outreg2 using Table_W9pol, replace dec(3) excel  ctitle(slang)
foreach sample in est_sample   {
	foreach pos in     vald_prom listleader_prom vald_ri_prom {
		preserve 
		keep if  `sample'==1 & nom==1 & `pos'!=.
		reghdfe `pos'_rel worker_lim i.vald_prev  stud age_b30- age_ab64 woman non_nordic non_oecd   if `sample'==1 & nom==1  & std_flex!=., abs(k_y_p) cluster(p_id)
		outreg2 using Table_W9pol, append dec(3) excel  ctitle(1 `pos'_`sample')
		reghdfe `pos'_rel worker_lim i.vald_prev stud  age_b30- age_ab64 woman non_nordic non_oecd    std_flex if `sample'==1 & nom==1, abs(k_y_p) cluster(p_id)
		outreg2 using Table_W9pol, append dec(3) excel  ctitle(2 `pos'_`sample')
		restore
	}
}

preserve 
*Produces the results presented in the lower pane of Table W10
keep if   vald_ri_altprom!=. 

reghdfe vald_ri_altprom_rel  worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(v_y_p)
outreg2 using Table_W11pol, replace dec(3) excel  ctitle(1 vald_ri_altprom)
reghdfe vald_ri_altprom_rel worker_lim i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd  , abs(v_y_p)
outreg2 using Table_W11pol, append dec(3) excel  ctitle(2 vald_ri_altprom)
reghdfe vald_ri_altprom_rel worker_lim  std_inc_res i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    , abs(v_y_p)
outreg2 using Table_W11pol, append dec(3) excel  ctitle( 3 vald_ri_altprom)
reghdfe vald_ri_altprom_rel worker_lim i.vald_prev std_inc_res stud age_b30- age_ab64 woman non_nordic non_oecd      if betyg_sd!=. , abs(v_y_p)
outreg2 using Table_W11pol, append dec(3) excel  ctitle(4 vald_ri_altprom)
reghdfe vald_ri_altprom_rel worker_lim  betyg_sd std_inc_res  i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    , abs(v_y_p)
outreg2 using Table_W11pol, append dec(3) excel  ctitle(5 vald_ri_altprom)
reghdfe vald_ri_altprom_rel worker_lim i.vald_prev std_inc_res stud age_b30- age_ab64 woman non_nordic non_oecd      if cognitive!=., abs(v_y_p)
outreg2 using Table_W11pol, append dec(3) excel  ctitle(6 vald_ri_altprom)
reghdfe vald_ri_altprom_rel worker_lim  std_inc_res cognitive i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    , abs(v_y_p)
outreg2 using Table_W11pol, append dec(3) excel  ctitle(7 vald_ri_altprom)
restore


*Produces the results presented in Table W11
preserve 
keep if  est_sample==1 & nom==1 
reghdfe re_nom_re worker_lim  stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(k_y_p) cluster(p_id)
outreg2 using Table_W12, append dec(3) excel  ctitle(1 all)
reghdfe re_nom_re worker_lim  stud age_b30- age_ab64 woman non_nordic non_oecd i.vald_prev  , abs(k_y_p) cluster(p_id)
outreg2 using Table_W12, append dec(3) excel  ctitle(2 all)
reghdfe re_nom_rel worker_lim   stud age_b30- age_ab64 woman non_nordic non_oecd if vald==1  , abs(k_y_p) cluster(p_id)
outreg2 using Table_W12, append dec(3) excel  ctitle(3 nom)
reghdfe re_nom_rel worker_lim   stud age_b30- age_ab64 woman non_nordic non_oecd i.vald_prev if vald==1  , abs(k_y_p) cluster(p_id)
outreg2 using Table_W12, append dec(3) excel  ctitle(4 nom)
restore

*Produces the results presented in the 3 lower panes of Table W12
reghdfe vald worker_isco stud age_b30- age_ab64 woman non_nordic non_oecd if  nom==1, abs(k_y_p)
outreg2 using Table_W13pol, replace dec(3) excel  ctitle(slang)	
foreach sample in est_sample   {
	foreach pos in     vald_prom listleader_prom vald_ri_prom {
		preserve 
		keep if  `sample'==1 & nom==1 & `pos'!=.
		reghdfe `pos'_rel  worker_isco stud age_b30- age_ab64 woman non_nordic non_oecd   if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_W13pol, append dec(3) excel  ctitle(1 `pos'_`sample')
		reghdfe `pos'_rel worker_isco i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd  if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_W13pol, append dec(3) excel  ctitle(2 `pos'_`sample')
		reghdfe `pos'_rel worker_isco  std_inc_res i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_W13pol, append dec(3) excel  ctitle( 3 `pos'_`sample')
		reghdfe `pos'_rel worker_isco i.vald_prev std_inc_res stud age_b30- age_ab64 woman non_nordic non_oecd     if `sample'==1 & nom==1 & betyg_sd!=. , abs(k_y_p)
		outreg2 using Table_W13pol, append dec(3) excel  ctitle(4 `pos'_`sample')
		reghdfe `pos'_rel worker_isco  betyg_sd std_inc_res  i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_W13pol, append dec(3) excel  ctitle(5 `pos'_`sample')
		reghdfe `pos'_rel worker_isco i.vald_prev std_inc_res stud age_b30- age_ab64 woman non_nordic non_oecd     if `sample'==1 & nom==1 & cognitive!=., abs(k_y_p)
		outreg2 using Table_W13pol, append dec(3) excel  ctitle(6 `pos'_`sample')
		reghdfe `pos'_rel worker_isco  std_inc_res cognitive i.vald_prev stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1, abs(k_y_p)
		outreg2 using Table_W13pol, append dec(3) excel  ctitle(7 `pos'_`sample')
		restore
	}
}
 

*Produces the results presented in the 3 lower panes of Table W13
reghdfe vald worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd if  nom==1, abs(k_y_p)
outreg2 using Table_W14pol, replace dec(3) excel  ctitle(slang)
foreach sample in est_sample   {
	foreach pos in     vald_prom listleader_prom vald_ri_prom {
		preserve 
		keep if  `sample'==1 & nom==1 & `pos'!=.
		reghdfe `pos'_rel worker_lim i.vald_prev  stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1 & ed_level!=., abs(k_y_p) cluster(p_id)
		outreg2 using Table_W14pol, append dec(3) excel  ctitle(1 `pos')
		reghdfe `pos'_rel worker_lim i.vald_prev stud  age_b30- age_ab64 woman non_nordic non_oecd     if `sample'==1 & nom==1, abs(k_y_p ed_level) cluster(p_id)
	outreg2 using Table_W14pol, append dec(3) excel  ctitle(2 `pos')
		reghdfe `pos'_rel worker_lim i.vald_prev  stud age_b30- age_ab64 woman non_nordic non_oecd    if `sample'==1 & nom==1 & ed_level!=. & ed_level<5, abs(k_y_p) cluster(p_id)
		outreg2 using Table_W14pol, append dec(3) excel  ctitle(3 `pos')		

		restore
	}
}


*Produces the results presented in the 3 lower panes of Table W14
reghdfe vald worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd if  nom==1, abs(k_y_p)
outreg2 using Table_W15pol, replace dec(3) excel  ctitle(slang)
foreach sample in est_sample   {
	foreach pos in     vald_prom listleader_prom vald_ri_prom {
		preserve 
		keep if  `sample'==1 & nom==1 & `pos'!=.
		reghdfe `pos'_rel worker_lim i.vald_prev  stud age_b30- age_ab64 woman non_nordic non_oecd   if `sample'==1 & nom==1  & allrelatedtasks!=., abs(k_y_p) cluster(p_id)
		outreg2 using Table_W15pol, append dec(3) excel  ctitle(1 `pos'_`sample')
		reghdfe `pos'_rel worker_lim i.vald_prev stud  age_b30- age_ab64 woman non_nordic non_oecd    allrelatedtasks  if `sample'==1 & nom==1, abs(k_y_p) cluster(p_id)
		outreg2 using Table_W15pol, append dec(3) excel  ctitle(2 `pos'_`sample')
		restore
	}
}

log close


	
	
